package com.xindong.paking.controller;

import com.xindong.paking.dtos.CarouselChartDTO;
import com.xindong.paking.dtos.CarouselChartDTO01;
import com.xindong.paking.dtos.CouponDTO;
import com.xindong.paking.entity.Coupon;
import com.xindong.paking.service.CarouselChartService;
import com.xindong.paking.service.CouponService;
import com.xindong.paking.utils.FileUtil;
import com.xindong.paking.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

import static com.xindong.paking.entity.constant.Constants.UPLOAD_FILE_SUCCESS;

@RestController
@RequestMapping("/parking/carousel-chart")
@Api(tags = "轮播图管理模块")
public class CarouselChartController {


    @Autowired
    private CarouselChartService carouselChartService;

    @PostMapping("queryByConForPage")
    @ApiOperation("根据条件分页查询轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id"),
            @ApiImplicitParam(name = "name", value = "图片名称"),
            @ApiImplicitParam(name = "status", value = "是否启用：Y/N"),
            @ApiImplicitParam(name = "pageCount", value = "页码,默认为第一页"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数,默认每页10条")
    })
    public Result queryByConForPage(@RequestBody CarouselChartDTO dto) {
        return carouselChartService.queryByConForPage(dto);
    }



    @GetMapping("queryByStatus")
    @ApiOperation("根据启用状态查询轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "是否启用：Y/N")
    })
    public Result queryByStatus(@RequestParam("status") String status){
        return carouselChartService.queryByStatus(status);
    }


    @PostMapping("deleteById")
    @ApiOperation("根据id删除轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "carouselChartId", value = "主键id")
    })
    public Result deleteById(@RequestParam("carouselChartIds") List<Integer> carouselChartIds){
        return carouselChartService.deleteById(carouselChartIds);
    }


    @PostMapping("insertCarouselChart")
    @ApiOperation("添加轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片文件"),
            @ApiImplicitParam(name = "name", value = "图片名称"),
            @ApiImplicitParam(name = "status", value = "是否启用：Y/N"),
            @ApiImplicitParam(name = "sort", value = "轮播序号")
    })
    public Result insertCarouselChart(@RequestBody CarouselChartDTO01 dto) {
        return carouselChartService.insertCarouselChart(dto);
    }


    @PostMapping("updateCarouselChart")
    @ApiOperation("更新轮播图信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id"),
            @ApiImplicitParam(name = "file", value = "图片文件"),
            @ApiImplicitParam(name = "name", value = "图片名称"),
            @ApiImplicitParam(name = "status", value = "是否启用：Y/N"),
            @ApiImplicitParam(name = "sort", value = "轮播序号")
    })
    public Result updateCarouselChart(@RequestBody CarouselChartDTO01 dto) {
        return carouselChartService.updateCarouselChart(dto);
    }


    @PostMapping("uploadFile")
    @ApiOperation("上传文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "图片文件")
    })
    public Result uploadFile(MultipartFile file){
        String[] upload = FileUtil.upload(file);
        return Result.success(UPLOAD_FILE_SUCCESS,upload[1]);
    }


}
